﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ylh.BLL;
using ExtAspNet;
using System.Data;

public partial class Module_DepartmentManger_Department :PageBase 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PreloadTv();
        }
    }

    private void PreloadTv()
    {
        Tree1.Nodes.Clear();

        if (Request.QueryString["DepartmentID"] != null)
        {
            //GetStaff(string ConStr, int StaffID)
            //GetStaffData(string ConStr, string DepartmentID)
            LoadTv(Request.QueryString["DepartmentID"].ToString());
        }
        else
        {
            Ylh.BLL.StaffBLL blls = new StaffBLL(DbConnectionStr);
            DataTable dt = blls.GetStaff( Convert.ToInt32( StaffID));
            LoadTv( dt.Rows[0]["DepartmentID"].ToString());
        }
    }


    private void LoadTv(string DepartmentID)
    {
        Ylh.BLL.DepartmentBLL blld = new DepartmentBLL(DbConnectionStr);

       DataTable dt= blld.GetDepartMentInfo(Convert.ToDecimal (DepartmentID));

       ExtAspNet.TreeNode Tn = new ExtAspNet.TreeNode();
       Tn.Text = dt.Rows[0]["DepartmentName"].ToString();
       Tn.NodeID = dt.Rows[0]["DepartmentID"].ToString();
       Tn.Expanded = true;
       

        Ylh.BLL.StaffBLL blls=new StaffBLL (DbConnectionStr);
        DataTable dts = blls.GetStaffData(dt.Rows[0]["DepartmentID"].ToString());

        ExtAspNet.TreeNode tn;
        foreach (DataRow dr in dts.Rows)
        { 
            tn= new ExtAspNet.TreeNode();
            tn.NodeID = dr["StaffID"].ToString();
            tn.NavigateUrl = "../StaffManger/StaffScore.aspx?StaffID=" + dr["StaffID"].ToString();
            tn.Target = "Staff";
            tn.Leaf = true;
            tn.Text = dr["StaffName"].ToString();
            Tn.Nodes.Add(tn);
        }
        Tree1.Nodes.Add(Tn);
    }
}